package drds.binlog.example;

import drds.binlog.client.Connector;
import drds.binlog.client.Connectors;
import drds.binlog.common.utils.AddressUtils;

import java.net.InetSocketAddress;

/**
 * 单机模式的测试例子
 *
 * @author jianghang 2013-4-15 下午04:19:20
 * @version 1.0.4
 */
public class SimpleCanalClientTest extends AbstractCanalClientTest
{

    public SimpleCanalClientTest(String destination)
    {
        super(destination);
    }

    public static void main(String args[])
    {
        // 根据ip，直接创建链接，无HA的功能
        String destination = "example";
        String ip = AddressUtils.getHostIp();
        Connector connector = Connectors.newSingleConnector(new InetSocketAddress(ip, 11111),
                destination,
                "",
                "");

        final SimpleCanalClientTest clientTest = new SimpleCanalClientTest(destination);
        clientTest.setConnector(connector);
        clientTest.start();
        Runtime.getRuntime().addShutdownHook(new Thread()
        {

            public void run()
            {
                try
                {
                    logger.info("## stop the canal client");
                    clientTest.stop();
                } catch (Throwable e)
                {
                    logger.warn("##something goes wrong when stopping canal:", e);
                } finally
                {
                    logger.info("## canal client is down.");
                }
            }

        });
    }

}
